Skip to content

Extend playwright coverage for threads (breadcrumbs & side-navbar navigation) #6632

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@ def __init__(self, page):
super().__init__(page)
self.utilities = Utilities(page)

# Locators related to the page breadcrumb.
self.breadcrumb_options = page.locator("ol#breadcrumbs li")
self.breadcrumb_links = page.locator("ol#breadcrumbs li a")
self.breadcrumb_link = lambda breadcrumb_name: page.locator(
"ol#breadcrumbs li").get_by_role("link", name=breadcrumb_name)

# Locators related to the Contributor Discussions side navbar.
self.contributor_discussions_side_navbar_header = page.locator(
"#for-contributors-sidebar ul li.sidebar-subheading")
self.contributor_discussions_side_navbar_items = page.locator(
"#for-contributors-sidebar ul li:not(.sidebar-subheading)")
self.contributor_discussions_side_navbar_item = lambda item_name: page.locator(
"#for-contributors-sidebar ul li:not(.sidebar-subheading)").get_by_role(
"link", name=item_name, exact=True)

# Locators related to the thread-actions section.
self.edit_thread_title_option = page.get_by_role("link", name="Edit Thread Title")
self.delete_this_thread_option = page.get_by_role("link", name="Delete this thread")
Expand Down Expand Up @@ -66,6 +81,30 @@ def __init__(self, page):
self.preview_reply_button = page.locator("button#preview")
self.post_reply_button = page.get_by_role("button", name="Post Reply")

def get_breadcrumb_options(self) -> list[str]:
"""
Get the breadcrumb options.
Returns:
list[str]: A list of breadcrumb options.
"""
return self._get_text_of_elements(self.breadcrumb_options)

def click_on_a_breadcrumb_link(self, breadcrumb_name: str):
"""
Click on a specific breadcrumb link.
Args:
breadcrumb_name (str): The name of the breadcrumb link.
"""
self._click(self.breadcrumb_link(breadcrumb_name))

def get_all_breadcrumb_link_names(self) -> list[str]:
"""
Get all breadcrumb link names.
Returns:
list[str]: A list of breadcrumb link names.
"""
return self._get_text_of_elements(self.breadcrumb_links)

def get_thread_meta_information(self) -> list[str]:
return self._get_text_of_elements(self.thread_meta)

Expand Down Expand Up @@ -236,3 +275,27 @@ def is_reply_textarea_visible(self) -> bool:
bool: True if the textarea is visible, False otherwise.
"""
return self._is_element_visible(self.post_reply_textarea)

def get_contributor_discussions_side_navbar_header(self) -> str:
"""
Get the header text of the Contributor Discussions side navbar.
Returns:
str: The header text of the side navbar.
"""
return self._get_text_of_element(self.contributor_discussions_side_navbar_header)

def get_contributor_discussions_side_navbar_items(self) -> list[str]:
"""
Get the text of all items in the Contributor Discussions side navbar.
Returns:
list[str]: A list of side navbar item texts.
"""
return self._get_text_of_elements(self.contributor_discussions_side_navbar_items)

def click_on_contributor_discussions_side_navbar_item(self, item_name: str):
"""
Click on a specific item in the Contributor Discussions side navbar.
Args:
item_name (str): The name of the item to click on.
"""
self._click(self.contributor_discussions_side_navbar_item(item_name))
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from playwright_tests.messages.auth_pages_messages.fxa_page_messages import FxAPageMessages
from playwright_tests.messages.contribute_messages.con_discussions.off_topic import \
OffTopicForumMessages
from playwright_tests.messages.homepage_messages import HomepageMessages
from playwright_tests.pages.sumo_pages import SumoPages


Expand Down Expand Up @@ -526,3 +527,156 @@ def test_sticky_this_thread(page: Page):
with allure.step("Deleting the thread"):
utilities.navigate_to_link(thread_link)
sumo_pages.contributor_thread_flow.delete_thread()


# C890978
@pytest.mark.contributorDiscussionsThreads
def test_thread_breadcrumbs(page: Page):
sumo_pages = SumoPages(page)
utilities = Utilities(page)

with allure.step("Signing in with a contributor and posting a new thread"):
utilities.start_existing_session(utilities.username_extraction_from_email(
utilities.user_secrets_accounts["TEST_ACCOUNT_MODERATOR"]
))
utilities.navigate_to_link(OffTopicForumMessages.PAGE_URL)
thread_title = (utilities.discussion_thread_data['thread_title'] + utilities.
generate_random_number(1, 1000))
sumo_pages.contributor_thread_flow.post_a_new_thread(
thread_title=thread_title,
thread_body=utilities.discussion_thread_data['thread_body']
)

with check, allure.step("Verifying that the thread title is displayed inside the list of "
"breadcrumbs"):
check.is_in(
thread_title,
sumo_pages.forum_thread_page.get_breadcrumb_options()
)

with check, allure.step("Clicking on all breadcrumb links and verifying that they redirect to "
"the correct page"):
for breadcrumb in sumo_pages.forum_thread_page.get_all_breadcrumb_link_names():
sumo_pages.forum_thread_page.click_on_a_breadcrumb_link(breadcrumb)
if breadcrumb == "Home":
check.equal(
utilities.get_page_url(),
HomepageMessages.STAGE_HOMEPAGE_URL_EN_US
)
elif breadcrumb == OffTopicForumMessages.PAGE_TITLE:
check.equal(
breadcrumb,
sumo_pages.forum_discussions_page.get_forum_discussions_page_title()
)
else :
check.equal(
breadcrumb,
sumo_pages.contributor_discussions_page.get_contributor_discussions_page_title(
)
)
utilities.navigate_back()

with allure.step("Deleting the article"):
sumo_pages.contributor_thread_flow.delete_thread()


# C3010845
@pytest.mark.contributorDiscussionsThreads
def test_forum_post_side_navbar_redirects(page: Page):
sumo_pages = SumoPages(page)
utilities = Utilities(page)

with allure.step("Signing in with a contributor account and navigating to the Off Topic forum "
"page"):
utilities.start_existing_session(utilities.username_extraction_from_email(
utilities.user_secrets_accounts['TEST_ACCOUNT_MODERATOR']
))
utilities.navigate_to_link(OffTopicForumMessages.PAGE_URL)

with allure.step("Creating a new forum thread"):
thread_title = utilities.discussion_thread_data['thread_title'] + (
utilities.generate_random_number(1, 1000))
sumo_pages.contributor_thread_flow.post_a_new_thread(
thread_title=thread_title,
thread_body=utilities.discussion_thread_data['thread_body']
)

navbar_items = sumo_pages.forum_thread_page.get_contributor_discussions_side_navbar_items()
for option in navbar_items:
with check, allure.step(f"Verifying navigation for side navbar option: {option}"):
sumo_pages.forum_thread_page.click_on_contributor_discussions_side_navbar_item(option)
check.equal(
sumo_pages.forum_discussions_page.get_forum_discussions_side_nav_selected_option(
).lower(),
option.lower()
)
expected_title = {
"Forum moderator discussions": "Forum Moderators",
"Article discussions": "English Knowledge Base Discussions",
"Mobile support discussions": "Mobile Support forum discussions",
"Off topic discussions": "Off Topic",
"Lost thread discussions": "Lost Threads"
}.get(option, option)
check.equal(
sumo_pages.forum_discussions_page.get_forum_discussions_page_title().lower(),
expected_title.lower()
)
utilities.navigate_back()

with allure.step("Deleting the thread"):
sumo_pages.contributor_thread_flow.delete_thread()


# C3010846
@pytest.mark.contributorDiscussionsThreads
@pytest.mark.parametrize("user", [None, 'simple_user', 'moderator'])
def test_forum_moderators_availability_inside_the_forum_post_page(page: Page, user):
sumo_pages = SumoPages(page)
utilities = Utilities(page)

utilities.start_existing_session(utilities.username_extraction_from_email(
utilities.user_secrets_accounts["TEST_ACCOUNT_MODERATOR"]
))

with allure.step("Navigating to the Contributor Discussions forum"):
utilities.navigate_to_link(OffTopicForumMessages.PAGE_URL)

with allure.step("Creating a new forum thread"):
thread_title = utilities.discussion_thread_data['thread_title'] + (
utilities.generate_random_number(1, 1000))
sumo_pages.contributor_thread_flow.post_a_new_thread(
thread_title=thread_title,
thread_body=utilities.discussion_thread_data['thread_body']
)

utilities.delete_cookies()

if user in ['simple_user', None]:
account = "TEST_ACCOUNT_12" if user == 'simple_user' else None
if account:
utilities.start_existing_session(utilities.username_extraction_from_email(
utilities.user_secrets_accounts[account]
))
with check, allure.step("Verifying that the 'Forum Moderators' forum is not available "
"inside the navbar"):
check.is_not_in(
"Forum moderator discussions",
sumo_pages.forum_thread_page.get_contributor_discussions_side_navbar_items()
)
else:
utilities.start_existing_session(utilities.username_extraction_from_email(
utilities.user_secrets_accounts["TEST_ACCOUNT_MODERATOR"]
))
with check, allure.step("Verifying that the 'Forum Moderators' forum is available inside "
"the navbar"):
check.is_in(
"Forum moderator discussions",
sumo_pages.forum_thread_page.get_contributor_discussions_side_navbar_items()
)

with allure.step("Deleting the thread"):
utilities.start_existing_session(utilities.username_extraction_from_email(
utilities.user_secrets_accounts["TEST_ACCOUNT_MODERATOR"]
))
utilities.navigate_to_link(utilities.get_page_url())
sumo_pages.contributor_thread_flow.delete_thread()